﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Qiniu.Http;
using SH.Common.Helper;
using SH.Customer.Application.IApplication.ICustomer;
using SH.Customer.Application.IApplication.IMenberCard;

namespace SH.Customer.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MemberCardController : ControllerBase
    {
        private readonly IMemberCardApplication _membercardApplication;

        public MemberCardController(IMemberCardApplication membercardApplication)
        {
            _membercardApplication = membercardApplication;
        }

        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="file">要上传的文件信息</param>
        /// <returns>上传的文件的文件名</returns>
        [HttpPost]
        public IActionResult UploadFile(IFormFile file)
        {
            // 文件保存的路径和文件名
            string saveFileName = Directory.GetCurrentDirectory() + @"\wwwroot\pic\" + file.FileName;
            // 上传
            using (FileStream fs = new FileStream(saveFileName, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            // 返回值（文件名）
            return Ok(file.FileName);
        }

        /// <summary>
        /// 添加会员卡
        /// </summary>
        /// <param name="cardDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> MemberCardAdd(MemberCardDto cardDto)
        {
            var result = await _membercardApplication.MemberCardAdd(cardDto);
            return Ok(result);
        }

        /// <summary>
        /// 了解会员卡详情
        /// </summary>
        /// <param name="mId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMemberCardDelitalAsync(int mId)
        {
            var result = await _membercardApplication.GetMemberCardDelitalAsync(mId);
            return Ok(result);
        }

        /// <summary>
        /// 会员信息修改
        /// </summary>
        /// <param name="cardDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult MemberCardUpdate(MemberCardDto cardDto)
        {
            var result = _membercardApplication.MemberCardUpdate(cardDto);
            return Ok(result);
        }
    }
}
